package org.example.server;
/**
 * @Description: TODO
 * @Author: sats@jz
 * @Date: 2024/12/24 15:37
 **/


import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServerRequest;

/**
 * @description TODO
 * @author sats@jz
 * @date 2024年12月24日 15:37
 */
public class VertxHttpServer implements HttpServer {
    @Override
    public void doStart(int port) {
        Vertx vertx = Vertx.vertx();
        io.vertx.core.http.HttpServer server = vertx.createHttpServer();

        server.requestHandler(request -> {
            System.out.println("request: " + request.method() + " " + request.uri());
            request.response()
                    .putHeader("content-type", "text/plain")
                    .end("Hello from Vert.c HTTP server!");
        });


        // 绑定请求处理器
        server.requestHandler(new HttpServerHandler());



        server.listen(port, result -> {
            if (result.succeeded()) {
                System.out.println("Server listening on port " + port);
            } else {
                System.out.println("Failed to start server: " + result.cause());
            }
        });
    }
}
